#pragma once

#include "common.h"

class CLock
{
private:
	CRITICAL_SECTION m_cs;

public:
	CLock()
	{
		InitializeCriticalSection(&m_cs);		               
	}

	~CLock()
	{
		DeleteCriticalSection(&m_cs);
	}

	void Lock()
	{
		EnterCriticalSection(&m_cs);
	}

	void Unlock()
	{
		LeaveCriticalSection(&m_cs);
	}
};


class Guard
{
public:
    Guard(CLock& l):m_lock(l)
    {
        m_lock.Lock();
    }

    ~Guard()
    {
        m_lock.Unlock();
    }
private:
    CLock& m_lock;
};
